home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / BenchMarks / Dhrystone / dhry_pack_1.c < prev    next >
C/C++ Source or Header  |  1993-01-25  |  10KB  |  391 lines

  1. /*
  2.  ****************************************************************************
  3.  *
  4.  *             "DHRYSTONE" Benchmark Program
  5.  *             -----------------------------
  6.  *                                          
  7.  *  Version:    C, Version 2.0
  8.  *                                          
  9.  *  File:    dhry_pack_1.c (part 2 of 3)
  10.  *
  11.  *  Date:    March 3, 1988
  12.  *
  13.  *  Author:    Reinhold P. Weicker
  14.  *
  15.  ****************************************************************************
  16.  */
  17.  
  18. #include "dhry_global.h"
  19.  
  20. /* Global Variables: */
  21.  
  22. Rec_Pointer    Ptr_Glob,
  23.         Next_Ptr_Glob;
  24. int        Int_Glob;
  25. Boolean        Bool_Glob;
  26. char        Ch_1_Glob,
  27.         Ch_2_Glob;
  28. int        Arr_1_Glob [50];
  29. int        Arr_2_Glob [50]    [50];
  30.  
  31. extern char    *malloc    ();
  32. Enumeration    Func_1 ();
  33.   /* forward declaration necessary since Enumeration may not simply be int */
  34.  
  35. #ifndef    REG
  36.     Boolean    Reg = false;
  37. #define    REG
  38.     /* REG becomes defined as empty    */
  39.     /* i.e.    no register variables    */
  40. #else
  41.     Boolean    Reg = true;
  42. #endif
  43.  
  44. /* variables for time measurement: */
  45.  
  46. #ifdef TIMES
  47. struct tms    time_info;
  48. extern    int    times ();
  49.         /* see library function    "times"    */
  50. #endif
  51. #ifdef TIME
  52. extern long    time();
  53.         /* see library function    "time"    */
  54. #endif
  55.  
  56. #define    Too_Small_Time 2
  57.         /* Measurements    should last at least 2 seconds */
  58.  
  59. long        Begin_Time,
  60.         End_Time,
  61.         User_Time;
  62. float        Microseconds,
  63.         Dhrystones_Per_Second;
  64.  
  65. /* end of variables for    time measurement */
  66.  
  67.  
  68. main ()
  69. /*****/
  70.  
  71.   /* main program, corresponds to procedures        */
  72.   /* Main and Proc_0 in    the Ada    version            */
  73.  
  74. {
  75.     One_Fifty    Int_1_Loc;
  76.   REG    One_Fifty    Int_2_Loc;
  77.     One_Fifty    Int_3_Loc;
  78.   REG    char        Ch_Index;
  79.     Enumeration    Enum_Loc;
  80.     Str_30        Str_1_Loc;
  81.     Str_30        Str_2_Loc;
  82.   REG    int        Run_Index;
  83.   REG    int        Number_Of_Runs;
  84.  
  85.  
  86.   /* Initializations */
  87.  
  88.   Next_Ptr_Glob    = (Rec_Pointer)    malloc (sizeof (Rec_Type));
  89.   Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
  90.  
  91.   Ptr_Glob->Ptr_Comp            = Next_Ptr_Glob;
  92.   Ptr_Glob->Discr            = Ident_1;
  93.   Ptr_Glob->variant.var_1.Enum_Comp    = Ident_3;
  94.   Ptr_Glob->variant.var_1.Int_Comp    = 40;
  95.   strcpy (Ptr_Glob->variant.var_1.Str_Comp, 
  96.       "DHRYSTONE PROGRAM, SOME STRING");
  97.   strcpy (Str_1_Loc, "DHRYSTONE    PROGRAM, 1'ST STRING");
  98.  
  99.   Arr_2_Glob [8][7] = 10;
  100.     /* Was missing in published program. Without this        */
  101.     /* initialization, Arr_2_Glob [8][7] would have    an        */
  102.     /* undefined value.                        */
  103.     /* Warning: With 16-Bit    processors and Number_Of_Runs >    32000,    */
  104.     /* overflow may    occur for this array element.            */
  105.  
  106.   printf ("\n");
  107.   printf ("Dhrystone Benchmark,    Version    2.0 (Language: C)\n");
  108.   printf ("\n");
  109.   if (Reg)
  110.   {
  111.     printf ("Program compiled with 'register' attribute\n");
  112.     printf ("\n");
  113.   }
  114.   else
  115.   {
  116.     printf ("Program compiled without 'register' attribute\n");
  117.     printf ("\n");
  118.   }
  119.   printf ("Please give the number of runs through the benchmark: ");
  120.   {
  121.     int n;
  122.     scanf ("%d", &n);
  123.     Number_Of_Runs = n;
  124.   }
  125.   printf ("\n");
  126.  
  127.   printf ("Execution starts, %d    runs through Dhrystone\n", Number_Of_Runs);
  128.  
  129.   /***************/
  130.   /* Start timer */
  131.   /***************/
  132.  
  133. #ifdef TIMES
  134.   times    (&time_info);
  135.   Begin_Time = (long) time_info.tms_utime;
  136. #endif
  137. #ifdef TIME
  138.   Begin_Time = time ( (long *) 0);
  139. #endif
  140.  
  141.   for (Run_Index = 1; Run_Index    <= Number_Of_Runs; ++Run_Index)
  142.   {
  143.  
  144.     Proc_5();
  145.     Proc_4();
  146.       /* Ch_1_Glob == 'A', Ch_2_Glob ==    'B', Bool_Glob == true */
  147.     Int_1_Loc =    2;
  148.     Int_2_Loc =    3;
  149.     strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND    STRING");
  150.     Enum_Loc = Ident_2;
  151.     Bool_Glob =    ! Func_2 (Str_1_Loc, Str_2_Loc);
  152.       /* Bool_Glob == 1    */
  153.     while (Int_1_Loc < Int_2_Loc)  /* loop body    executed once */
  154.     {
  155.       Int_3_Loc    = 5 * Int_1_Loc    - Int_2_Loc;
  156.     /* Int_3_Loc ==    7 */
  157.       Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
  158.     /* Int_3_Loc ==    7 */
  159.       Int_1_Loc    += 1;
  160.     } /* while */
  161.       /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7    */
  162.     Proc_8 (Arr_1_Glob,    Arr_2_Glob, Int_1_Loc, Int_3_Loc);
  163.       /* Int_Glob == 5 */
  164.     Proc_1 (Ptr_Glob);
  165.     for    (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob;    ++Ch_Index)
  166.                  /*    loop body executed twice */
  167.     {
  168.       if (Enum_Loc == Func_1 (Ch_Index,    'C'))
  169.       /* then, not executed    */
  170.     {
  171.     Proc_6 (Ident_1, &Enum_Loc);
  172.     strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
  173.     Int_2_Loc = Run_Index;
  174.     Int_Glob = Run_Index;
  175.     }
  176.     }
  177.       /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7    */
  178.     Int_2_Loc =    Int_2_Loc * Int_1_Loc;
  179.     Int_1_Loc =    Int_2_Loc / Int_3_Loc;
  180.     Int_2_Loc =    7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
  181.       /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
  182.     Proc_2 (&Int_1_Loc);
  183.       /* Int_1_Loc == 5    */
  184.  
  185.   } /* loop "for Run_Index" */
  186.  
  187.   /**************/
  188.   /* Stop timer    */
  189.   /**************/
  190.   
  191. #ifdef TIMES
  192.   times    (&time_info);
  193.   End_Time = (long) time_info.tms_utime;
  194. #endif
  195. #ifdef TIME
  196.   End_Time = time ( (long *) 0);
  197. #endif
  198.  
  199.   printf ("Execution ends\n");
  200.   printf ("\n");
  201.   printf ("Final values    of the variables used in the benchmark:\n");
  202.   printf ("\n");
  203.   printf ("Int_Glob:        %d\n", Int_Glob);
  204.   printf ("       should be:    %d\n", 5);
  205.   printf ("Bool_Glob:        %d\n", Bool_Glob);
  206.   printf ("       should be:    %d\n", 1);
  207.   printf ("Ch_1_Glob:        %c\n", Ch_1_Glob);
  208.   printf ("       should be:    %c\n", 'A');
  209.   printf ("Ch_2_Glob:        %c\n", Ch_2_Glob);
  210.   printf ("       should be:    %c\n", 'B');
  211.   printf ("Arr_1_Glob[8]:    %d\n", Arr_1_Glob[8]);
  212.   printf ("       should be:    %d\n", 7);
  213.   printf ("Arr_2_Glob[8][7]:    %d\n", Arr_2_Glob[8][7]);
  214.   printf ("       should be:    Number_Of_Runs + 10\n");
  215.   printf ("Ptr_Glob->\n");
  216.   printf ("  Ptr_Comp:        %d\n", (int) Ptr_Glob->Ptr_Comp);
  217.   printf ("       should be:    (implementation-dependent)\n");
  218.   printf ("  Discr:        %d\n", Ptr_Glob->Discr);
  219.   printf ("       should be:    %d\n", 0);
  220.   printf ("  Enum_Comp:        %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
  221.   printf ("       should be:    %d\n", 2);
  222.   printf ("  Int_Comp:        %d\n", Ptr_Glob->variant.var_1.Int_Comp);
  223.   printf ("       should be:    %d\n", 17);
  224.   printf ("  Str_Comp:        %s\n", Ptr_Glob->variant.var_1.Str_Comp);
  225.   printf ("       should be:    DHRYSTONE PROGRAM, SOME    STRING\n");
  226.   printf ("Next_Ptr_Glob->\n");
  227.   printf ("  Ptr_Comp:        %d\n", (int) Next_Ptr_Glob->Ptr_Comp);
  228.   printf ("       should be:    (implementation-dependent), same as above\n");
  229.   printf ("  Discr:        %d\n", Next_Ptr_Glob->Discr);
  230.   printf ("       should be:    %d\n", 0);
  231.   printf ("  Enum_Comp:        %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
  232.   printf ("       should be:    %d\n", 1);
  233.   printf ("  Int_Comp:        %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
  234.   printf ("       should be:    %d\n", 18);
  235.   printf ("  Str_Comp:        %s\n",
  236.                 Next_Ptr_Glob->variant.var_1.Str_Comp);
  237.   printf ("       should be:    DHRYSTONE PROGRAM, SOME    STRING\n");
  238.   printf ("Int_1_Loc:        %d\n", Int_1_Loc);
  239.   printf ("       should be:    %d\n", 5);
  240.   printf ("Int_2_Loc:        %d\n", Int_2_Loc);
  241.   printf ("       should be:    %d\n", 13);
  242.   printf ("Int_3_Loc:        %d\n", Int_3_Loc);
  243.   printf ("       should be:    %d\n", 7);
  244.   printf ("Enum_Loc:        %d\n", Enum_Loc);
  245.   printf ("       should be:    %d\n", 1);
  246.   printf ("Str_1_Loc:        %s\n", Str_1_Loc);
  247.   printf ("       should be:    DHRYSTONE PROGRAM, 1'ST    STRING\n");
  248.   printf ("Str_2_Loc:        %s\n", Str_2_Loc);
  249.   printf ("       should be:    DHRYSTONE PROGRAM, 2'ND    STRING\n");
  250.   printf ("\n");
  251.  
  252.   User_Time = End_Time - Begin_Time;
  253.  
  254.   if (User_Time    < Too_Small_Time)
  255.   {
  256.     printf ("Measured time too small to    obtain meaningful results\n");
  257.     printf ("Please increase number of runs\n");
  258.     printf ("\n");
  259.   }
  260.   else
  261.   {
  262. #ifdef TIME
  263.     Microseconds = (float) User_Time * Mic_secs_Per_Second 
  264.             / (float) Number_Of_Runs;
  265.     Dhrystones_Per_Second = (float) Number_Of_Runs / (float) User_Time;
  266. #else
  267.     Microseconds = (float) User_Time * Mic_secs_Per_Second 
  268.             / ((float) HZ *    ((float) Number_Of_Runs));
  269.     Dhrystones_Per_Second = ((float) HZ    * (float) Number_Of_Runs)
  270.             / (float) User_Time;
  271. #endif
  272.     printf ("Microseconds for one run through Dhrystone: ");
  273.     printf ("%6.1f \n",    Microseconds);
  274.     printf ("Dhrystones    per Second:             ");
  275.     printf ("%6.1f \n",    Dhrystones_Per_Second);
  276.     printf ("\n");
  277.   }
  278.   
  279. }
  280.  
  281.  
  282. Proc_1 (Ptr_Val_Par)
  283. /**********************/
  284.  
  285. REG Rec_Pointer    Ptr_Val_Par;
  286.     /* executed    once */
  287. {
  288.   REG Rec_Pointer Next_Record =    Ptr_Val_Par->Ptr_Comp;    
  289.                     /* == Ptr_Glob_Next */
  290.   /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp,    */
  291.   /* corresponds to "rename" in    Ada, "with" in Pascal        */
  292.   
  293.   structassign (*Ptr_Val_Par->Ptr_Comp,    *Ptr_Glob); 
  294.   Ptr_Val_Par->variant.var_1.Int_Comp =    5;
  295.   Next_Record->variant.var_1.Int_Comp 
  296.     = Ptr_Val_Par->variant.var_1.Int_Comp;
  297.   Next_Record->Ptr_Comp    = Ptr_Val_Par->Ptr_Comp;
  298.   Proc_3 (&Next_Record->Ptr_Comp);
  299.     /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp 
  300.             == Ptr_Glob->Ptr_Comp */
  301.   if (Next_Record->Discr == Ident_1)
  302.     /* then, executed */
  303.   {
  304.     Next_Record->variant.var_1.Int_Comp    = 6;
  305.     Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp, 
  306.        &Next_Record->variant.var_1.Enum_Comp);
  307.     Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
  308.     Proc_7 (Next_Record->variant.var_1.Int_Comp, 10, 
  309.        &Next_Record->variant.var_1.Int_Comp);
  310.   }
  311.   else /* not executed */
  312.     structassign (*Ptr_Val_Par,    *Ptr_Val_Par->Ptr_Comp);
  313. } /* Proc_1 */
  314.  
  315.  
  316. Proc_2 (Int_Par_Ref)
  317. /******************/
  318.     /* executed    once */
  319.     /* *Int_Par_Ref == 1, becomes 4 */
  320.  
  321. One_Fifty   *Int_Par_Ref;
  322. {
  323.   One_Fifty  Int_Loc;  
  324.   Enumeration    Enum_Loc;
  325.  
  326.   Int_Loc = *Int_Par_Ref + 10;
  327.   do /*    executed once */
  328.     if (Ch_1_Glob == 'A')
  329.       /* then, executed    */
  330.     {
  331.       Int_Loc -= 1;
  332.       *Int_Par_Ref = Int_Loc - Int_Glob;
  333.       Enum_Loc = Ident_1;
  334.     } /* if */
  335.   while    (Enum_Loc != Ident_1); /* true */
  336. } /* Proc_2 */
  337.  
  338.  
  339. Proc_3 (Ptr_Ref_Par)
  340. /**********************/
  341.     /* executed    once */
  342.     /* Ptr_Ref_Par becomes Ptr_Glob */
  343.  
  344. Rec_Pointer *Ptr_Ref_Par;
  345.  
  346. {
  347.   if (Ptr_Glob != Null)
  348.     /* then, executed */
  349.     *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
  350.   else /* not executed */
  351.     Int_Glob = 100;
  352.   Proc_7 (10, Int_Glob,    &Ptr_Glob->variant.var_1.Int_Comp);
  353. } /* Proc_3 */
  354.  
  355.  
  356.  
  357. Proc_4 () /* without parameters    */
  358. /*******/
  359.     /* executed    once */
  360. {
  361.   Boolean Bool_Loc;
  362.  
  363.   Bool_Loc = Ch_1_Glob == 'A';
  364.   Bool_Glob = Bool_Loc | Bool_Glob;
  365.   Ch_2_Glob = 'B';
  366. } /* Proc_4 */
  367.  
  368.  
  369. Proc_5 () /* without parameters    */
  370. /*******/
  371.     /* executed    once */
  372. {
  373.   Ch_1_Glob = 'A';
  374.   Bool_Glob = false;
  375. } /* Proc_5 */
  376.  
  377.  
  378.     /* Procedure for the assignment    of structures,        */
  379.     /* if the C compiler doesn't support this feature    */
  380. #ifdef    NOSTRUCTASSIGN
  381. memcpy (d, s, l)
  382. register char    *d;
  383. register char    *s;
  384. register int    l;
  385. {
  386.     while (l--) *d++ = *s++;
  387. }
  388. #endif
  389.  
  390.  
  391.